package com.eaoa.uc.account.bo;

import java.util.Set;

import com.eaoa.base.EABaseBusinessObject;
import com.eaoa.dao.pub.PubAccountDAO;
import com.eaoa.vo.pub.PubAccount;
import com.eaoa.vo.pub.PubCustomer;
import com.stony.core.exception.RunException;


public class AccountAddPubCusotmersBO extends EABaseBusinessObject {
	
	private Long accountno;
	private Long customerno;

	private static PubAccountDAO accountDAO = new PubAccountDAO();

	public AccountAddPubCusotmersBO(Long accountno, Long customerno) {
		super();
		this.accountno = accountno;
		this.customerno = customerno;
	}

	protected void performBusinessLogic() {

		PubAccount po = (PubAccount) accountDAO.load(accountno);

		Set customers = po.getPubCustomers();

		PubCustomer customer = new PubCustomer(customerno);

		if (!customers.contains(customer)) {
			customers.add(customer);
		} else {
			throw new RunException("error.employeecustomer.exist");
		}

		accountDAO.update(po);

	}

}